package org.example.tliaswebmanagerment.service.Impl;

import org.example.tliaswebmanagerment.mapper.DeptMapper;
import org.example.tliaswebmanagerment.pojo.Dept;
import org.example.tliaswebmanagerment.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.swing.*;
import java.time.LocalDateTime;
import java.util.List;


@Service
public class DeptServiceImpl implements DeptService {

    @Autowired
    private DeptMapper deptMapper;

    /**
     * 查询所有部门
     */
    @Override
    public List<Dept> findAll() {
        return deptMapper.findAll();
    }

    /**
     * 删除部门
     */
    @Override
    public void deleteById(Integer id) {
        deptMapper.deleteById(id);
    }

    /**
     * 新增部门
     */
    @Override
    public void add(Dept dept) {
        LocalDateTime now = LocalDateTime.now();
        dept.setCreateTime(now);
        dept.setUpdateTime(now);
        System.out.println("createTime: " + dept.getCreateTime());
        System.out.println("updateTime: " + dept.getUpdateTime());
        deptMapper.add(dept);
    }

    /**
     * 根据id查询部门
     */
    @Override
    public Dept findById(Integer id) {
        return deptMapper.findById(id);
    }

    /**
     * 修改部门
     */
    @Override
    public void update(Dept dept) {

        LocalDateTime now = LocalDateTime.now();
        dept.setUpdateTime(now);
        deptMapper.update(dept);
    }




}
